import java.telephony.*;
import java.telephony.events.*;

/*
 * The MyObserver class implements the CallObserver and
 * recieves all Call-related events.
 */
 
public class MyObserver implements CallObserver {
 
  public void callChangedEvent(CallEv[] evlist) {
 
    for (int i = 0; i < evlist.length; i++) {
 
      if (evlist[i] instanceof TermConnEv) {
        TerminalConnection termconn = null;
        String name = null;
 
        try {
          TermConnEv tcev = (TermConnEv)evlist[i];
          TerminalConnection termconn = tcev.getTerminalConnection();
          Terminal term = termconn.getTerminal();
          String name = term.getName();
        } catch (Exception excp) {
          // Handle exceptions.
        }

        String msg = "TerminalConnection to Terminal: " + name + " is ";
 
        if (evlist[i].getID() == TermConnActiveEv.ID) {
          System.out.println(msg + "ACTIVE");
        }
        else if (evlist[i].getID() == TermConnRingingEv.ID) {
          System.out.println(msg + "RINGING")
 
          /* Answer the telephone Call */
          try {
            termconn.answer();
          } catch (Exception excp) {
            // Handle Exceptions;
          }
        }
        else if (evlist[i].getID() == TermConnDropped.ID) {
          System.out.println(msg + "DROPPED");
        }
      }  
    }
  }
}